package com.kpf.springcloud.controller;

import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.service.FeignClientUserServer;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shiwen
 * @date 2021/2/28
 */
@RestController
@Api(value = "token相关接口", description = "token相关接口") //swagger接口配置
public class TokenConsumerController {

    @Autowired
    private FeignClientUserServer feignClientUserServer;

    /**
     * 根据userId创建token
     *
     * @param userId
     * @param roleType
     */
    @PostMapping("/consumer/token/createToken")
    public ResultJson<Boolean> createToken(@RequestParam(value = "userId") int userId, @RequestParam(value = "roleType") int roleType){
        return feignClientUserServer.createToken(userId, roleType);
    }

    /**
     * 校验token, 从上下文中获取userId进行校验
     */
    @GetMapping("/consumer/token/verifyToken")
    public ResultJson<String> verifyToken(){
        return feignClientUserServer.verifyToken();
    }

    @GetMapping("/consumer/token/loginOut")
    public ResultJson loginOut() {
        return feignClientUserServer.loginOut();
    }

}